package com.bsierp.util.mail;


import java.io.FileInputStream;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;




public class MailSender {
	
	
	public static void main(String[] args) throws Exception{
		
		MailSender ms=new MailSender();
		ms.sendMail("bewithmeallmylife", "fengloveyan1314", "220.181.12.14", "359709421@qq.com", "359709421@qq.com", "text","<input type=\"text\"  />");
		
	}
	
	
	
	
	public void sendMail(final String sender_id,final String sender_password,String sender_smtphost,String sender_address,String recipient_address,String mail_subject,String mail_content) throws Exception{

		Properties props = new Properties();
		props.setProperty("mail.smtp.auth", "true");
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", sender_smtphost);
		
		Session session = Session.getInstance(props,
				new Authenticator()
				{
					protected PasswordAuthentication getPasswordAuthentication()
					{
						return new PasswordAuthentication(sender_id,sender_password);
					}
				}
		);
		session.setDebug(true);
		
		Message msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress(sender_address));
		msg.setSubject(mail_subject);
		msg.setRecipients(RecipientType.TO, 
				InternetAddress.parse(recipient_address));
		msg.setContent(mail_content, "text/html;charset=gbk");
		Transport.send(msg);
		
		
	}
	
	
	
	

}
